package com.chen.nongansampling.presenter;

import android.content.Context;

import com.chen.nongansampling.bean.SimpleRequest;
import com.chen.nongansampling.bean.notice.NoticeBean;
import com.chen.nongansampling.manager.DataManager;
import com.chen.nongansampling.model.CallbackData;
import com.chen.nongansampling.presenterView.NoticeView;

import java.util.List;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class NoticePresenter extends BasePresenter {

    private Context mContext;
    private NoticeView  noticeView;
    private CallbackData<List<NoticeBean>> callbackData;

    public NoticePresenter(Context mContext) {
        this.mContext = mContext;
    }

    @Override
    public void BindPresentView(Object presentView) {
        noticeView=(NoticeView) presentView;
    }


    public void getNoticeResponseInfo(SimpleRequest simpleRequest) {
        DataManager.getInstance(mContext).getNoticesResponseInfo(simpleRequest)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new Observer<CallbackData<List<NoticeBean>>>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(CallbackData<List<NoticeBean>> listCallbackData) {
                        callbackData = listCallbackData;

                    }




                    @Override
                    public void onError(Throwable e) {
                        noticeView.onError(e.toString());
                    }

                    @Override
                    public void onComplete() {
                        if (callbackData != null) {
                            noticeView.getNoticeList(callbackData);
                        }
              //          NoticePresenter.super.compositeDisposable.dispose();
                    }
                });
    }
}
